package com.koushikdutta.ion;

import android.graphics.Bitmap;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Point;
import android.graphics.Rect;
import com.koushikdutta.ion.bitmap.BitmapInfo;
import com.koushikdutta.ion.bitmap.IonBitmapCache;

public class LoadBitmapRegion extends BitmapCallback {
    public LoadBitmapRegion(Ion ion, String key, BitmapRegionDecoder decoder, Rect region, int inSampleSize) {
        super(ion, key, true);
        final BitmapRegionDecoder bitmapRegionDecoder = decoder;
        final Rect rect = region;
        final int i = inSampleSize;
        final String str = key;
        Ion.getBitmapLoadExecutorService().execute(new Runnable() {
            public void run() {
                try {
                    Bitmap bitmap = IonBitmapCache.loadRegion(bitmapRegionDecoder, rect, i);
                    if (bitmap == null) {
                        throw new Exception("failed to load bitmap region");
                    }
                    LoadBitmapRegion.this.report(null, new BitmapInfo(str, null, new Bitmap[]{bitmap}, new Point(bitmap.getWidth(), bitmap.getHeight())));
                } catch (Exception e) {
                    LoadBitmapRegion.this.report(e, null);
                }
            }
        });
    }
}
